package com.example.threaddemo;

import lombok.extern.slf4j.Slf4j;

import java.util.concurrent.TimeUnit;

/**
 * @Description
 * @Date 2021/8/8
 * @Created by Jonathan
 */
@Slf4j
public class StopThread implements Runnable {
    public static void main(String[] args) throws Exception {
        Thread thread = new Thread(new StopThread());
        thread.start();
        TimeUnit.SECONDS.sleep(2);
        thread.interrupt();
    }

    @Override
    public void run() {
        int num = 0;
        while (!Thread.currentThread().isInterrupted() && num < Integer.MAX_VALUE / 2) {
            if (num % 10000 == 0) {
                log.info("{}是10000的倍数", num);
            }
            num++;
        }
    }
}
